package com.sentiment.mail;

import java.io.UnsupportedEncodingException;
import java.util.List;

import javax.mail.MessagingException; 

import org.apache.log4j.Logger; 

public class SendMailOnTime { 

    public static Logger log = null ; 

    static { 
       log = Logger.getLogger (SendMailOnTime. class ); 
    } 

    /** 
      * @param args 
     * @throws UnsupportedEncodingException 
      */ 

    public static void sendMail(String subject,String str) throws UnsupportedEncodingException { 
       MailBean mail = new MailBean(); 
       try { 
           mail.sendMessage( "smtp.sina.com" , "grateful_r@sina.com" , 
                  subject , str); 
       } catch (MessagingException e) { 
           System. out .println( "mail send error !" ); 
           log .debug( "mail send error !" + e.getMessage()); 
           e.printStackTrace(); 
       } 
       System. out .println( "Mail have been sended ." ); 
    } 

    /** 
      * 给一个指定邮箱发送指定的邮件内容 
      * @param str 
     * @throws UnsupportedEncodingException 
      */ 

    public static void sendMail(String toMail,String subject, String content) throws UnsupportedEncodingException { 

       MailBean mail = new MailBean(); 
       try { 
           mail.sendMessage( "smtp.sina.com" , "grateful_r@sina.com" , toMail, 
                  subject , content); 
       } catch (MessagingException e) { 
           System. out .println( "mail send error !" ); 
           log .debug( "mail send error !" + e.getMessage()); 
           e.printStackTrace(); 
       } 
       System. out .println( "Mail have been sended ." ); 
    } 

    /** 
      * 指定目的邮箱数组进行群发 create date:2008- 8- 15 author:Administrator 
      * @param toMail 
      * @param content 
     * @throws UnsupportedEncodingException 
      */ 

    public static void sendMail(List<String> toMail, String subject, String content) throws UnsupportedEncodingException { 

       MailBean mail = new MailBean(); 
       try { 
           mail.sendMessage( "smtp.sina.com" , "grateful_r@sina.com" , toMail, 
                  subject , content); 
       } catch (MessagingException e) { 
           System. out .println( "mail send error !" ); 
           log .debug( "mail send error !" + e.getMessage()); 
           e.printStackTrace(); 
       } 
       System. out .println( "Mail have been sended ." ); 
    } 

} 



